
<?php

$head ="

<label>PREFEITURA MUNICIPAL DE FORTALEZA </label><br>
<label>INSTITUTO DR. JOS&Eacute; FROTA</label><br>
<label>CENTRO DE ASSIST&Ecirc;NCIA TOXICOL&Oacute;GICA - CEATOX-IJF</label><p>
<label>Tabela 5: Casos Registrados de Intoxica&ccedil;&atilde;o Humana por AGENTE T&Oacute;XICO x Zona</label><p>
<label>Periodo: " . $datainicio. " &agrave; " . $datafim . "</label><p>
<table border=\"1\">
                <thead>
                    <tr>
                        <th>AGENTE TOXICO</th>
                        <th>RURAL</th>
                        <th>URBANA</th>
                        <th>TOTAL</th>
                        <th>%</th>
                    </tr>
                </thead>
                <tbody>";
                    $body = "";
                        $i = $total["0"]->total;
                        $grupoid = "";
                        $pertotal = 0;
                        $subtotal = 0;
                        $totalr = 0;
                        $totalu = 0;
                        $totalgeral = 0;
                        foreach ($listaurbana as $item):
                             
                             
                             $zorarural = 0;
                             $zoraurbana = $item->total;
                              foreach ($listarural as $value):
                                     if ($item->gruporesposta_id == $value->gruporesposta_id ):
                                             $zorarural = $value->total;
                                     endif;

                               endforeach;
                               
                               if ($item->gruporesposta_id != $grupoid ):
                                       $subtotal = $zorarural + $zoraurbana;
                                       $totalr = $totalr+ $zorarural;
                                       $totalu = $totalu+ $zoraurbana;
                                       $per = ($subtotal/$i)*100;
                             $body = $body . "
                            <tr>
                                <td>" . utf8_decode($item->descricao) . " </td>
                                <td>" . $zorarural . " </td>
                                <td>" . $zoraurbana . " </td>
                                <td>" .  $subtotal . "</td>
                                <td>" . substr($per,0,4) . " %</td>
                        </tr> ";

                         endif;
                         $per = ($subtotal/$i)*100;
                         $totalgeral = $totalgeral + $subtotal;
                         $pertotal = (($totalr +$totalu)/$i)*100;
                         $grupoid = $item->gruporesposta_id;
                         
                                endforeach;
                                $perr = ($totalr/$i)*100;
                                $peru = ($totalu/$i)*100;
                           $body = $body .
                                "
                                <tr>
                                <td >TOTAL</td>
                                <td>" . $totalr . "</td>
                                <td>" . $totalu . "</td>
                                <td>" .  $totalgeral . "</td>
                                <td>" . substr($pertotal,0,5) ." %</td>
                                </tr>
                                <tr>";
$footer = "</tbody></table>";
                                $html = $head . $body . $footer;?>

<?php
require_once(BASEPATH.'plugins/dompdf/dompdf_config.inc.php');
    $dompdf = new DOMPDF();
    $dompdf->load_html($html);
    $dompdf->set_paper('letter', 'landscape');
    $dompdf->render();
    $dompdf->stream("zona - vitima.pdf");
?>